package com.lib76.socket.client;

import com.lib76.socket.CommunicationServer;
import com.lib76.socket.SocketObject;
import com.lib76.socket.message.JsonSocketMessage;
import com.lib76.socket.model.SocketChannel;

public class RtdSocketClient2Runner {

	public static void main(String[] args) {
		boolean result = false;
		result = CommunicationServer.messageProtocolInitial(CommunicationServer.class.getResourceAsStream("/protocol2.0.xml"), null);
		result = CommunicationServer.socketInitial(CommunicationServer.class.getResourceAsStream("/communication_client_config.xml"), null);

		if(result){
			SocketObject client =CommunicationServer.getSocketObject("client");
			if(client.run()){
				SocketChannel channel = client.getClientChannel();
				JsonSocketMessage msg = (JsonSocketMessage)client.getRequestMessage("rtdLogin");
				msg.writeString("serialNum", "RTD002");
				msg.writeString("ip", "127.0.0.1");
				
				if(channel.write(msg)){
					System.out.println("发送命令成功");
					
					JsonSocketMessage heartMsg = (JsonSocketMessage)client.getRequestMessage("rtdHeart");
					if(channel.write(heartMsg)){
						System.out.println("心跳发送成功");
					}
					
				}else{
					System.out.println("发送命令失败");
				}
			}
		}
	}

}
